/*******************************************************************************

[Last updated: June 4th, 2024]

This script does not perform any analysis or data cleaning. 
Its purpose is to generate LaTeX code in *.txt files for inclusion in the manuscript.

Each table in the manuscript corresponds to a block of 3-part code:

	Part 1: "table start" defines the table structure and its label
	Part 2: "write horizontal" generates the LaTeX code containing the estimates
	Part 3: "table end" adds the table note

For Part 2, users will notice a repetitive pattern:

	write_horizontal: 	Invokes the [write_horizontal] program
	/q_p_m4_NLU/: 		Extracts estimates from the relevant matrix, 
						in this case, from the matrix storing estimates for the 
						use of non-lethal force
	/title/: 			Specifies the title for the outcome
	/CmCoSePvQv/: 		Selects which components of the matrix to include 
						in the table. Here, Control Mean, Coefficient, SE, 
						p-value, and q-value are written

	For more details, see the [shell] function scripts.

*******************************************************************************/




* Load the data file -----------------------------------------------------------

	if "$individual_run" != "Yes" {
	di "Program Stopped: Make sure you load the parameters in master.do"
	e
	}
	
	
* Table 3: Main outcomes -------------------------------------------------------

		gl month_segments months_1_4_t 
		table_start_horizontal ///
		${report_folder}/Admin_key_outcomes.txt ///
		"Key Outcomes in The Field" 130 "one_p"
		midrule

			write_horizontal 	q_p_m4_NLU	1000		"Uses of non-lethal force" 		CmCoSePvQv
			write_horizontal 	q_p_m4_DAR 	1000		"Discretionary arrests" 		CmCoSePvQv	
			write_horizontal 	q_p_m4_OI	1			"Officer injuries (days off)" 	CmCoSePvQv
			write_horizontal 	q_p_m4_AI	1			"Officer activities (index)" 	RcCoSePvQv

		local N : di %9.0fc q_p_m4_AI_months_1_4_t[1,6]
		write_end end_key_common `N'
		
		table_end "$end_key_common" Admin_key_outcomes
		
		
* Table B13: Auxiliary outcomes -------------------------------------------------

		gl month_segments months_1_4_t
		table_start_horizontal ///
		${report_folder}/Admin_App_additional.txt ///
		"Auxiliary Outcomes in The Field" 200 "one_p"
		midrule

			file write table "\\"
			file write table "\multicolumn{8}{c}{\textbf{Panel A: Specific Use of Force Measures}}  \\"
			midrule
			
			write_horizontal 	q_p_m4_UL1		1000	"Uses of force (level 1 only)" 				CmCoSePvRq
			write_horizontal 	q_p_m4_UL2		1000	"Uses of force (level 2 only)"				CmCoSePvRq
			write_horizontal 	q_p_m4_AU		1000	"Uses of force (levels 1-3)" 				CmCoSePvRq
			write_horizontal 	q_p_m4_LTU		1000	"Uses of force (levels 2-3 only)"			CmCoSePvRq
			
			file write table "\\"
			file write table "\multicolumn{8}{c}{\textbf{Panel B: Additional TRR Outcomes}}  \\"
			midrule
			
			write_horizontal 	q_p_m4_NLUSI 	1000	"Subject injuries (officer reported)"		CmCoSePvQv
			write_horizontal	q_p_m4_NLUSA	1000	"Subject allegations of injuries"			CmCoSePvQv
			write_horizontal	q_p_m4_NLUH		1000	"Hospitalization"							CmCoSePvQv
			write_horizontal	q_p_m4_NLUSH 	1000	"Hospitalizations and either subject alleged injury or officer reported an injury" CmCoSePvQv
			write_horizontal	q_p_m4_TTT		1	 	"Tactics used in uses of force incidents (index)" RcCoSePvQv
		
		local N : di %9.0fc q_p_m4_TTT_months_1_4_t[1,6]
		write_end end_auxiliary `N'
		
		table_end "$end_auxiliary" Admin_App_additional
		
* Table B14: Downstream --------------------------------------------------------

		gl month_segments months_1_4_t
		table_start_horizontal ///
		${report_folder}/Admin_App_Downstream.txt ///
		"Downstream Consequences from Officers' Actions" 180 "one_p" 
		midrule

			write_horizontal 	q_p_m4_AW		1000	"Commendations and awards" 						CmCoSePvQv
			write_horizontal 	q_p_m4_COM		1000	"Total complaints"								CmCoSePvQv
			write_horizontal 	q_p_m4_COMI		1		"Force and abuse related complaints (index)" 	RcCoSePvQv
			
		local N : di %9.0fc q_p_m4_COMI_months_1_4_t[1,6]
		write_end end_downstream `N'
		
		table_end "$end_downstream" Admin_App_Downstream
		
		
* Table B16: Three months ------------------------------------------------------

		gl month_segments months_1_3_t
		table_start_horizontal ///
		${report_folder}/Admin_App_3month.txt ///
		"Field Outcomes Three Months after the Training" 135 "one_p" 
		midrule
			write_horizontal 	q_p_m3_NLU 	1000		"Uses of non-lethal force" 		CmCoSePvQv
			write_horizontal 	q_p_m3_DAR 	1000		"Discretionary arrests" 		CmCoSePvQv	
			write_horizontal 	q_p_m3_OI	1			"Officer injuries (days off)" 	CmCoSePvQv
			write_horizontal 	q_p_m3_AI	1			"Officer activities (index)" 	RcCoSePvQv
		
		local N : di %9.0fc q_p_m3_AI_months_1_3_t[1,6]
		write_end end_key_3m `N'
		
		table_end "$end_key_3m" Admin_App_3month

		
* Table B29: 12 months ----------------------------------------------------------

		gl month_segments months_1_12_t
		table_start_horizontal ///
		${report_folder}/Admin_App_12month.txt ///
		"Field Outcomes Twelve Months after the Training" 135 "one_p" 
		midrule
			write_horizontal 	q_p_m12_NLU 1000		"Uses of non-lethal force" 		CmCoSePvQv
			write_horizontal 	q_p_m12_DAR 1000		"Discretionary arrests" 		CmCoSePvQv	
			write_horizontal 	q_p_m12_OI	1			"Officer injuries (days off)" 	CmCoSePvQv
			write_horizontal 	q_p_m12_AI	1			"Officer activities (index)" 	RcCoSePvQv
		
		local N : di %9.0fc q_p_m12_AI_months_1_12_t[1,6]
		write_end end_key_3m `N'
		
		table_end "$end_key_12m" Admin_App_12month

* Table B17: Alternative specifications -----------------------------------------
		
		gl month_segments months_1_4_t 
		table_start_horizontal ///
		${report_folder}/Admin_key_outcomes_alternative.txt ///
		"Key Field Outcomes - Robustness to Controls" 135 "one_p"
		midrule

			file write table "\\"
			file write table "\multicolumn{8}{c}{\textbf{Panel A: LASSO-selected Covariates}}  \\"
			midrule
			
				write_horizontal 	q_p_M4v_NLU		1000		"Uses of non-lethal force" 		CmCoSePvQv
				write_horizontal 	q_p_M4v_DAR 	1000		"Discretionary arrests" 		CmCoSePvQv	
				write_horizontal 	q_p_M4v_OI		1			"Officer injuries (days off)" 	CmCoSePvQv
				write_horizontal 	q_p_M4v_AI		1			"Officer activities (index)" 	RcCoSePvQv

		midrule
		
			file write table "\\"
			file write table "\multicolumn{8}{c}{\textbf{Panel B: No Additional Covariates}}  \\"
			midrule
			
				write_horizontal 	q_p_S4_NLU		1000		"Uses of non-lethal force" 		CmCoSePvQv
				write_horizontal 	q_p_S4_DAR 		1000		"Discretionary arrests" 		CmCoSePvQv
				write_horizontal 	q_p_S4_OI		1			"Officer injuries (days off)" 	CmCoSePvQv
				write_horizontal 	q_p_S4_AI		1			"Officer activities (index)" 	RcCoSePvQv
		
		local N : di %9.0fc q_p_M4v_AI_months_1_4_t[1,6]
		write_end end_key_no_base `N'
		
		table_end "$end_key_outcomes_alternative" Admin_App_alternative
		
* Table B19: Heterogeneous treatment effects : By Experience, Gender and race --

	table_start_horizontal_het_panel ///
	${report_folder}/Admin_App_het_experience_race_gender.txt ///
	"Effects on Field Outcomes by Officer Experience, Race, and Gender" 130 ""  
	
	file write table "\multicolumn{10}{c}{\textbf{Panel A: Effects on Field Outcomes by Officer Experience}}  \\" _n ///
			" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \textbf{Experience} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n ///
			"\hhline{ ~~~---~---} \\[-1em]" _n
			
		write_horizontal_het_one 	het_experience_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_experience_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
	
		file write table "\\" _n 
		midrule
	
		file write table "\multicolumn{10}{c}{\textbf{Panel B: Effects on Field Outcomes by Officer Race}}  \\" _n ///
		" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \textbf{White} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n  ///
			"\hhline{ ~~~---~---} \\[-1em]" _n

		write_horizontal_het_one 	het_dwhite_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_dwhite_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
		
		file write table "\\" _n 
		midrule

		file write table "\multicolumn{10}{c}{\textbf{Panel C: Effects on Field Outcomes by Officer Gender}}  \\" _n ///
		" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \textbf{Male} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n  ///
			"\hhline{ ~~~---~---} \\[-1em]" _n

		write_horizontal_het_one 	het_dmale_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_dmale_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
		
	
	table_end "$end_key_het_e_race_gender" Admin_App_het_experience_race_gender
	
	
	
	
* Table B21: Heterogeneous treatment effects : By Baseline outcomes ------------

	table_start_horizontal_het_panel ///
	${report_folder}/Admin_App_het_baseline.txt ///
	"Effects by Baseline Measures of Field Outcomes" 130 ""  
	
	file write table "\multicolumn{10}{c}{\textbf{Panel A: Effects on Field Outcomes by Baseline Use of Non-lethal Force}}  \\" _n ///
		" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Uses of} \\ \textbf{Non-lethal Force}  \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n  ///
			"\hhline{ ~~~---~---} \\[-1em]" _n

		write_horizontal_het_one 	het_bNLU_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_bNLU_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
		
		file write table "\\" _n 
		midrule
	
	file write table "\multicolumn{10}{c}{\textbf{Panel B: Effects on Field Outcomes by Baseline Discretionary Arrests}}  \\" _n ///
			" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Discretionary Arrests} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n ///
			"\hhline{ ~~~---~---} \\[-1em]" _n
			
		write_horizontal_het_one 	het_bDAR_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_bDAR_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
		
		
		file write table "\\" _n 
		midrule
		
		file write table "\multicolumn{10}{c}{\textbf{Panel C: Effects on Field Outcomes by Baseline Arrests}}  \\" _n ///
		" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Arrests} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n  ///
			"\hhline{ ~~~---~---} \\[-1em]" _n

		write_horizontal_het_one 	het_pArr_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_pArr_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
		
		
		file write table "\\" _n 
		midrule
		
		file write table "\multicolumn{10}{c}{\textbf{Panel D: Effects on Field Outcomes by Baseline Complaints}}  \\" _n ///
		" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Complaints} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n  ///
			"\hhline{ ~~~---~---} \\[-1em]" _n

		write_horizontal_het_one 	het_bCOM_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_bCOM_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
				
	local N : di %9.0fc het_bDAR_NLU_months_1_4_t[1,8]
	write_end end_arr_baseline `N'
	table_end "$end_arr_baseline" Admin_App_het_baseline
	
	
* Table B22: Heterogeneous treatment effects : By Crime Rate -------------------

	table_start_horizontal_het_panel ///
	${report_folder}/Admin_App_het_crime.txt ///
	"Effects on Field Outcomes by Crime Rate" 130 "Crim Rate"  
	
	file write table "\multicolumn{10}{c}{\textbf{Panel A: Effects on Field Outcomes by Violent Crime Rate}}  \\" _n ///
		" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Violent Crime Rate} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n  ///
			"\hhline{ ~~~---~---} \\[-1em]" _n

		write_horizontal_het_one 	het_vcrime_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_vcrime_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
	
		
		file write table "\\" _n 
		midrule
	
	file write table "\multicolumn{10}{c}{\textbf{Panel B: Effects on Field Outcomes by Crime Rate}}  \\" _n ///
			" &  & & \multicolumn{3}{c}{\textbf{Sit-D}} &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Crime Rate} \end{tabular} } \\  " _n ///
			"\hhline{ ~~~===~===}" _n ///
			"\\[-1em]" _n ///
			" & & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} & &  \multicolumn{1}{c}{Coef} &  \multicolumn{1}{c}{SE} &  \multicolumn{1}{c}{p-value} \\ &   & &  \multicolumn{1}{c}{(1)} &  \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} & &  \multicolumn{1}{c}{(4)} &  \multicolumn{1}{c}{(5)} &  \multicolumn{1}{c}{(6)} \\ " _n ///
			"\hhline{ ~~~---~---} \\[-1em]" _n
			
		write_horizontal_het_one 	het_crime_NLU_months_1_4_t			1	1000	"Uses of non-lethal force"
		write_horizontal_het_one 	het_crime_DAR_months_1_4_t			1	1000	"Discretionary arrests" 
		
	
	local N : di %9.0fc het_crime_NLU_months_1_4_t[1,8]
	write_end end_arr_crime `N'
	table_end "$end_arr_crime" Admin_App_het_crime
	
	